package com.john.http.core.util;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * 〈一句话功能简述〉<br/>
 * 〈功能详细描述〉
 *
 * @author jiangguangtao on 2016/4/28.
 */
public class SimpleBeanUtil {

    /**
     * 设置发展值
     *
     * @param beanObject
     * @param fieldName
     * @param objVal
     */
    public static void setValue(Object beanObject, String fieldName, Object objVal) {
        if (null == beanObject) {
            throw new NullPointerException("bean对象不能为null");
        }
        if (StringUtils.isBlank(fieldName)) {
            throw new NullPointerException("设置属性时属性名称不能为空");
        }
        if (null == objVal) {
            return;
        }

        try {
            BeanUtils.setProperty(beanObject, fieldName, objVal);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}